package dcore.id;

/**
 * ID生成器
 * @author djin
 */
public final class IdUtil {
    private static Snowflake snowflake;

    /**
     * 获取ID生成方式
     * @return
     */
    public static Snowflake getSnowflake() {
        if(snowflake == null){
            setSnowflake(new SnowflakeByIp());
        }
        return snowflake;
    }

    /**
     * 设置ID生成方式
     * @param snowflake
     */
    public static void setSnowflake(Snowflake snowflake) {
        IdUtil.snowflake = snowflake;
    }

    /**
     * 生成ID
     * @return
     */
    public synchronized static long nextId(){
        return getSnowflake().nextId();
    }
}
